<%@ page session="true" buffer="16kb" import="java.sql.*,java.util.*,java.text.*"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%
response.setDateHeader("Expires", 0); // date in the past
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // HTTP/1.1 
response.addHeader("Cache-Control", "post-check=0, pre-check=0"); 
response.addHeader("Pragma", "no-cache"); // HTTP/1.0 
%>
<% Locale locale = Locale.getDefault();
locale = new Locale("zh","CN"); 
response.setLocale(locale);%>
<% session.setMaxInactiveInterval(30*60); %>
<% 
String login = (String) session.getAttribute("project1_status");
if (login == null || !login.equals("login")) {
response.sendRedirect("login.jsp");
response.flushBuffer(); 
return; 
}%>
<%int ewAllowAdmin = 16; 
int ewCurSec = 31;%>
<% String userid = (String) session.getAttribute("project1_status_UserID"); 
Integer userlevel = (Integer) session.getAttribute("project1_status_UserLevel"); 
if (userid == null && userlevel != null && (userlevel.intValue() != -1) ) {	response.sendRedirect("login.jsp");
	response.flushBuffer(); 
	return; 
}%>
<%@ include file="db.jsp" %>
<%@ include file="jspmkrfn.jsp" %>
<%
String tmpfld = null;
String escapeString = "\\\\'";

// Single delete record
String key = request.getParameter("key");
if (key == null || key.length() == 0 ) {
	response.sendRedirect("account_infolist.jsp");
	response.flushBuffer();
	return;
}
String sqlKey = "`ID`=" + "'" + key.replaceAll("'",escapeString) + "'";

// Get action
String a = request.getParameter("a");
if (a == null || a.length() == 0) {
	a = "I";	// Display with input box
}

// Open Connection to the database
try{
	Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
	ResultSet rs = null;
	if (a.equals("I")){ // Display
		String strsql = "SELECT * FROM `account_info` WHERE " + sqlKey;
		if (((Integer) session.getAttribute("project1_status_UserLevel")).intValue() != -1 ) { // Non system admin
				strsql = strsql + " AND (`NICK` = '" + (String) session.getAttribute("project1_status_UserID") + "')";
		}
		rs = stmt.executeQuery(strsql);
		if (!rs.next()) {
			response.sendRedirect("account_infolist.jsp");
		}else{
			rs.beforeFirst();
		}
	}else if (a.equals("D")){ // Delete
		String strsql = "DELETE FROM `account_info` WHERE " + sqlKey;
		if (session.getAttribute("project1_status_UserLevel") != null && ((Integer) session.getAttribute("project1_status_UserLevel")).intValue() != -1 ) { // Non system admin
				strsql = strsql + " AND (`NICK` = '" + (String) session.getAttribute("project1_status_UserID") + "')";
		}
		stmt.executeUpdate(strsql);
		stmt.close();
		stmt = null;
		conn.close();
		conn = null;
		response.sendRedirect("account_infolist.jsp");
		response.flushBuffer();
		return;
	}
%>
<%@ include file="header.jsp" %>
<div class="content">
	<div class="search">
		<p><span class="jspmaker table_name">删除该条信息<br></span></p>
		<a class="jspmaker back" href="account_infolist.jsp">返回</a>
	</div>
	<form action="account_infodelete.jsp" method="post">
	<input type="hidden" name="a" value="D">
	<table border="0" cellspacing="1" cellpadding="4" bgcolor="#CCCCCC">
		<tr bgcolor="#594FBF">
			<td><span class="jspmaker" style="color: #FFFFFF;">账号</span>&nbsp;</td>
			<td><span class="jspmaker" style="color: #FFFFFF;">密码</span>&nbsp;</td>
			<td><span class="jspmaker" style="color: #FFFFFF;">用户名</span>&nbsp;</td>
		</tr>
	<%
	int recCount = 0;
	while (rs.next()){
		recCount ++;
		String bgcolor = "#FFFFFF"; // Set row color
	%>
	<%
		if (recCount%2 != 0 ) { // Display alternate color for rows
			bgcolor = "#F5F5F5";
		}
	%>
	<%
		String x_ID = "";
		String x_PWD = "";
		String x_NICK = "";
	
		// ID
		if (rs.getString("ID") != null){
			x_ID = rs.getString("ID");
		}
		else{
			x_ID = "";
		}
	
		// PWD
		if (rs.getString("PWD") != null){
			x_PWD = rs.getString("PWD");
		}
		else{
			x_PWD = "";
		}
	
		// NICK
		if (rs.getString("NICK") != null){
			x_NICK = rs.getString("NICK");
		}
		else{
			x_NICK = "";
		}
	%>
		<tr bgcolor="<%= bgcolor %>">
		<input type="hidden" name="key" value="<%= HTMLEncode(key) %>">
			<td class="jspmaker"><% out.print(x_ID); %>&nbsp;</td>
			<td class="jspmaker"><% out.print(x_PWD); %>&nbsp;</td>
			<td class="jspmaker"><% out.print(x_NICK); %>&nbsp;</td>
	  </tr>
	<%
	}
	rs.close();
	rs = null;
	stmt.close();
	stmt = null;
	conn.close();
	conn = null;
	}catch (SQLException ex){
		out.println(ex.toString());
	}
	%>
	</table>
	<input class="editbutton" type="submit" name="Action" value="删除">
	</form>
</div>
<%@ include file="footer.jsp" %>
